/**
 * 版权所有:版权所有(C) 2020，卓信科技
 * 系统名称:FOL
 * 文件名称:FolRequestFolMobileController
 * 模块名称:FolRequestFolMobileController
 * 创建日期:2020年10月9日 上午9:51:10
 * 作        者:wangyihan
 * 内容摘要:FolRequestFolMobileController
 */
package com.zx.emanage.postLoanManage.web;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.zx.emanage.postLoanManage.service.impl.FolRequestForMobileServiceImpl;
import com.zx.emanage.postLoanManage.service.impl.FolRequestForReimburseMobileServiceImpl;
import com.zx.emanage.postLoanManage.vo.FolRequestForMobileSearchBeanVO;
import com.zx.emanage.user.service.IUserService;
import com.zx.emanage.user.vo.PmPersonnel;
import com.zx.emanage.util.gen.ResultHelper;
import com.zx.emanage.util.gen.SysUtil;
import com.zx.emanage.util.gen.entity.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

/**
 * 版权所有:版权所有(C) 2020，卓信科技
 * 系统名称:IFC2020-卓信普惠金融云平台
 * 文件名称:FolRequestFolMobileController
 * 模块名称:FolRequestFolMobileController
 * 创建日期:2020年10月9日上午9:51:10
 * 作 者:wangyihan
 * 内容摘要:FolRequestFolMobileController
 */
@Controller
public class FolRequestFolMobileController
{
    @Autowired
    private IUserService userService;

    /**
     * @param HttpServletRequest request, String param_json
     * @return
     * @Title: doFOLMethodForMoa
     * @Description: 动态获取方法
     * @author: wangyihan
     * @time: 2020年10月9 上午10:56:49
     * history: 1、2020年10月9 上午10:56:49 wangyihan 创建方法
     */
    @RequestMapping(value = "/folm/doFOLMethodForMoa.do", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object methodReflect(HttpServletRequest request, String param_json)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 将参数转成map
        Map<String, Object> paramMap = new HashMap<String, Object>();
        Object result = new Object();
        try
        {
            paramMap = JSONObject.parseObject(param_json, new TypeReference<Map<String, Object>>()
            {
            });
            // 保存操作日志
            try
            {
                // 登录人
                PmPersonnel personnel = new PmPersonnel();
                SysLog sysLog = new SysLog();
                sysLog.setUser_id(
                        paramMap.get("user_id") != null ? Integer.valueOf(paramMap.get("user_id").toString()) : null);
                sysLog.setType("移动端操作");
                sysLog.setOper_behavior("对应请求方法:" + paramMap.get("method_name") + "  请求参数:" + param_json);
                SysUtil.saveLog(sysLog, personnel);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            FolRequestForMobileSearchBeanVO queryInfo = new FolRequestForMobileSearchBeanVO();
            queryInfo.setParamMap(paramMap);
            queryInfo.setParam_json(param_json);
            Class<?> herosClass = FolRequestForMobileServiceImpl.class;
            Method m = herosClass
                    .getMethod(paramMap.get("method_name").toString(), FolRequestForMobileSearchBeanVO.class);
            Object service = herosClass.newInstance();
            result = m.invoke(service, queryInfo);
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (SecurityException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return result;
    }

    /**
     * 方法名称: FolRequestFolMobileController
     * 内容摘要: TODO()
     *
     * @return java.lang.Object
     * @Param [request, param_json]
     * @Author: wuguoqiang
     * @time: 2020/10/10 11:58
     **/
    @RequestMapping(value = "/folm/doFOLReimburseMethodForMoa.do", method = { RequestMethod.GET, RequestMethod.POST })
    @ResponseBody
    public Object doFOLReimburseMethodForMoa(HttpServletRequest request, @RequestParam("param_json") String param_json)
    {
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 将参数转成map
        Map<String, Object> paramMap = new HashMap<String, Object>();
        Object result = new Object();
        try
        {
            paramMap = JSONObject.parseObject(param_json, new TypeReference<Map<String, Object>>()
            {
            });
            // 保存操作日志
            try
            {
                // 登录人
                PmPersonnel personnel = new PmPersonnel();
                SysLog sysLog = new SysLog();
                sysLog.setUser_id(
                        paramMap.get("user_id") != null ? Integer.valueOf(paramMap.get("user_id").toString()) : null);
                sysLog.setType("移动端操作");
                sysLog.setOper_behavior("对应请求方法:" + paramMap.get("method_name") + "  请求参数:" + param_json);
                SysUtil.saveLog(sysLog, personnel);
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            FolRequestForMobileSearchBeanVO queryInfo = new FolRequestForMobileSearchBeanVO();
            queryInfo.setParamMap(paramMap);
            queryInfo.setParam_json(param_json);
            Class<?> herosClass = FolRequestForReimburseMobileServiceImpl.class;
            Method m = herosClass
                    .getMethod(paramMap.get("method_name").toString(), FolRequestForMobileSearchBeanVO.class);
            Object service = herosClass.newInstance();
            result = m.invoke(service, queryInfo);
        }
        catch (NoSuchMethodException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (SecurityException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (IllegalAccessException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (IllegalArgumentException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (InvocationTargetException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (InstantiationException e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            resMap.put("ret_data", null);
            resMap.put("ret_msg", e.getMessage());
            resMap.put("ret_code", ResultHelper.RET_ERROR);
        }
        return result;
    }

}
